home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / fakecrt.arc / FAKECRT.ASM next >
Assembly Source File  |  1991-08-28  |  4KB  |  162 lines

  1.     IDEAL
  2.     MODEL TPASCAL
  3.     DATASEG
  4. EXTRN ExtraKey : BYTE
  5.     CODESEG
  6. ; These routines are Copyright 1991 by Reuben Sumner.
  7. ; This file is the assembly source code to routines found in FakeCrt.Pas
  8. ; Unlike the provided Crt unit in Turbo Pascal these routines are fully
  9. ; redirectable (except where noted) and in some cases more reliable
  10. ; As well there is no wasteful startup code assosociated with this unit
  11.  
  12. PROC Sound FAR Hz : WORD
  13. ; Procedure Sound (Hz : Word);
  14. ; These procedure are almost identical to those in the Crt unit and are
  15. ; only provided for compatibility (I was having fun OK!). These interface
  16. ; directly with the hardware and are thus not redirectable
  17. FreqDiv = 1193180
  18. PUBLIC Sound
  19.     mov        bx,[Hz]                ; Load BX with frequency
  20.     mov        ax,34DCh
  21.     mov        dx,0012h            ; Load DX:AX with frequency divisor
  22.     cmp        bx,dx                ; Check for a divide overflow
  23.     jle        Done
  24.     div        bx                    ; Perform division
  25.     mov        bx,ax                ; Save result
  26.     in        al,61h                ; Read Programmable Peripheral Interface (PPI)
  27.     test    al,11b                ; Make sure speaker is enabled
  28.     jnz        SetFrequency        ; If it is don't waste our time
  29.     or        al,11b
  30.     out        61h,al                ; Send out new value with speaker enabled
  31.     mov        al,0B6h
  32.     out        43h,al                ; Get timer ready
  33. SetFrequency:
  34.     mov        al,bl                ; Get saved value from BX
  35.     out        42h,al
  36.     mov        al,bh
  37.     out        42h,al                ; Write out the high and low order bytes
  38. Done:
  39.     ret                            ; We're outta here!
  40. ENDP Sound
  41.  
  42. PROC NoSound FAR
  43. ; Procedure NoSound;
  44. PUBLIC NoSound
  45.     in    al,61h                    ; Read PPI setting
  46.     and    al,(not 0011b)
  47.     out    61h,al                    ; Disable speaker
  48.     ret
  49. ENDP NoSound
  50.  
  51. PROC ReadKey FAR
  52. ; Function ReadKey : Char;
  53. ; This function is identical in usage to the ReadKey in the Crt unit
  54. ; however this one can have its input redirected and supports F11 and F12
  55. PUBLIC ReadKey
  56.     mov    ah,07h                    ; Unfiltered character input without echo
  57.     int    21h
  58.     ret
  59. ENDP ReadKey
  60.  
  61. PROC KeyPressed
  62. PUBLIC KeyPressed
  63.     mov    ah,0Bh                    ; Check input status
  64.     int    21h
  65.     and    al,0FEh                    ; 0FFh if character waiting covert to Boolean
  66.     ret
  67. ENDP KeyPressed
  68.  
  69. PROC Delay FAR ms : WORD
  70. ; Procedure Delay (ms : Word);
  71. ; This is a very handy machine independant delay function works well
  72. PUBLIC Delay
  73.     mov    ax,[ms]                    ; Load ms count
  74.     mov    cx,1000
  75.     mul    cx                        ; Multiply by 1000
  76.     mov    cx,dx                    ; Load into correct registers for int 15h
  77.     mov    dx,ax
  78.     mov    ah,86h                    ; Delay function
  79.     int    15h                        ; Do it!
  80.     ret
  81. ENDP Delay
  82.  
  83. PROC RKey FAR
  84. ; Function RKey : Word;
  85. ; This function requires a bit of explanation. This function is designed
  86. ; as a replacement for ReadKey. Unlike ReadKey it reports a word instead of
  87. ; a character. If the low byte of the word is 0 then it is a extended key (F1)
  88. ; In that case the high byte contains the regular code reported by the second
  89. ; call to ReadKey. This should work with F11 and F12 (unlike ReadKey in the Crt
  90. ; unit) on almost all computers
  91. PUBLIC RKey
  92.     mov ax,40h
  93.     mov es,ax
  94.     xor ah,ah                    ; Read keyboard
  95.     test [BYTE PTR es:96h],10000b; 101 keyboard flag at 40:96
  96.     jz  NormalKeyboard
  97.     add ah,10h                ; Read Enhanced
  98. NormalKeyboard:
  99.     int 16h                    ; Call int 16h function 10h or 00h
  100.     cmp    al,0E0h                ; hidden E0?
  101.     jne    RKeyDone
  102.     or    ah,ah                ; ASCII E0?
  103.     jz    RKeyDone
  104.     xor    al,al
  105. RKeyDone:
  106.     ret
  107. ENDP RKey
  108.  
  109. PROC SReadKey
  110. ; Function SReadKey : Char;
  111. ; Totally compatible with Crt's ReadKey but will use F11 and F12 and is
  112. ; not redirectable
  113. PUBLIC SReadKey
  114.     cmp    [ExtraKey],0
  115.     jnz    GiveNextCh
  116.     mov ax,40h
  117.     mov es,ax
  118.     xor ah,ah                    ; Read keyboard
  119.     test [BYTE PTR es:96h],10000b; 101 keyboard flag at 40:96
  120.     jz  SNormalKeyboard
  121.     add ah,10h                ; Read Enhanced
  122. SNormalKeyboard:
  123.     int 16h                    ; Call int 16h function 10h or 00h
  124.     cmp    al,0E0h
  125.     jne    CheckFor0
  126.     or    ah,ah
  127.     jnz    ExtendedKey2
  128. CheckFor0:
  129.     or    al,al
  130.     jz    ExtendedKey
  131.     ret
  132. ExtendedKey2:
  133.     xor    al,al
  134. ExtendedKey:
  135.     mov    [ExtraKey],ah
  136.     ret
  137. GiveNextCh:
  138.     mov    al,[ExtraKey]
  139.     mov    [ExtraKey],0
  140.     ret
  141. ENDP SReadKey
  142.  
  143. PROC RKeyPressed FAR
  144. ; Function RKeyPressed : Boolean
  145. PUBLIC RKeyPressed
  146.     mov ax,40h
  147.     mov es,ax
  148.     mov ah,01h                ; Keyboard status
  149.     test [BYTE PTR es:96h],10000b        ; 101 keyboard flag
  150.     jz  NormalKeyboard2
  151.     add ah,10h                ; Read Enhanced
  152. NormalKeyboard2:
  153.     int 16h                    ; Call int 16h function 11h or 01h
  154.     jz  NoKeyWaiting        ; Zero flag set if no key waiting
  155.     mov al,1
  156.     jmp RKeyPressedX
  157. NoKeyWaiting:
  158.     xor al,al
  159. RKeyPressedX:
  160.     ret
  161. ENDP RKeyPressed
  162. END